Repository navigation
Conversation
Type the module fixture as a module, give the dataset helper an explicit construction path and annotate the vector stub, then drop the file from the strict-mode exclusion list.
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46368 +/- ##
========================================
Coverage 90.30% 90.30%
========================================
Files 6493 6496 +3
Lines 408263 408617 +354
Branches 81859 81893 +34
========================================
+ Hits 368670 369017 +347
- Misses 33189 33199 +10
+ Partials 6404 6401 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`AbstractVectorFactory.init_vector` and `Vector.__init__` declared `attributes` as a bare `list`, so every caller and override had to treat the entries as `Any`. The list only ever carries metadata field names, so it is declared as `list[str]`, and `Dataset.index_struct_dict` gets the `dict[str, Any] | None` it actually returns. With those types in place the vector factory test no longer needs to build its dataset by `setattr`-ing untyped overrides onto an instance: the helper takes the two fields the tests actually vary as real parameters.
There was a problem hiding this comment.
2 inline suggestions at 3b5d7f585b, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
| vector_factory_module: types.ModuleType, caplog: pytest.LogCaptureFixture | ||
| ) -> None: | ||
| """Progress logs must report the batch count, not a text count with the raw remainder.""" | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) |
There was a problem hiding this comment.
avoid __new__ here?
There was a problem hiding this comment.
Updated in d1e57ad8. The progress test now constructs a real Vector, uses a real SQLAlchemy session and production resolve_vector_type/factory path, and no longer uses Vector.__new__ or patches the factory. It asserts the externally visible 1/2 and 2/2 progress logs and processor batch sizes.
| def test_create_skips_empty_text_documents_before_embedding(vector_factory_module): | ||
| def test_create_skips_empty_text_documents_before_embedding(vector_factory_module: types.ModuleType) -> None: | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) | ||
| vector._embeddings = MagicMock() |
| def test_add_texts_with_optional_duplicate_check(vector_factory_module): | ||
| def test_add_texts_with_optional_duplicate_check(vector_factory_module: types.ModuleType) -> None: | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) | ||
| vector._embeddings = MagicMock() |
|
|
||
| def test_add_texts_filters_empty_documents_before_duplicate_check(vector_factory_module): | ||
| def test_add_texts_filters_empty_documents_before_duplicate_check(vector_factory_module: types.ModuleType) -> None: | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) |
| def test_filter_duplicate_texts_and_getattr(vector_factory_module): | ||
| def test_filter_duplicate_texts_and_getattr(vector_factory_module: types.ModuleType) -> None: | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) | ||
| vector.text_exists = MagicMock(side_effect=lambda doc_id: doc_id == "dup") |
asukaminato0721
left a comment
There was a problem hiding this comment.
CI is failing: Style Check / Python Style. Please fix it. 1 inline suggestion at 8599680381, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 5 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at d1e57ad8a1, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 5 review threads are still unresolved.
dify-codereview
| return [[0.1] for _ in texts] | ||
|
|
||
| @override | ||
| def embed_multimodal_documents(self, multimodel_documents: list[dict[str, object]]) -> list[list[float]]: |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
This is an override of the production Embeddings interface, whose multimodal inputs are open dictionaries. This test fake does not parse the mapping or inspect any keys; it returns one stable vector per input. The test is for vector batch progress, so I’m keeping the override compatible with the existing interface rather than adding a production schema here.
|
|
||
| def test_create_skips_empty_text_documents_before_embedding(vector_factory_module): | ||
| def test_create_skips_empty_text_documents_before_embedding(vector_factory_module: types.ModuleType) -> None: | ||
| vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector) |
There was a problem hiding this comment.
Fixed in f44ad12: this test now constructs a real Vector with a SQLAlchemy session and typed recording adapters. It still checks that empty and whitespace-only input never reaches embedding or the backend. All 55 vector factory unit tests passed, and strict Pyrefly reported zero diagnostics for the changed file.
What
Removes
core/rag/datasource/vdb/test_vector_factory.pyfrom the strict-mode exclusion list inapi/tests/unit_tests/pyrefly.tomland fixes the 68 diagnostics it was hiding.How
vector_factory_modulefixture returnsimportlib.reload(...), so it is annotatedtypes.ModuleType._datasethelper keeps its**overridesflexibility but constructs the record throughDataset(...)and applies the remaining keys withsetattr;Dataset(**values)produced 13bad-argument-typediagnostics because the SQLAlchemy constructor is not statically typed for arbitrary string keys.index_structcolumn stays writable whileindex_struct_dictis a read-only property, so the helper keeps translating the dict form into the column before construction._attributesis assignedlist[str]()rather than annotated (assigning to a non-self attribute cannot carry an annotation).No test logic, assertion or expected value was changed.
Verification
No
# pyrefly: ignore, no# type: ignore, notyping.cast, noAny.